import pandas, duckdb
import os
from utils.path_utils import get_project_root
from database.duckdb.duckdb_base import get_connection


def run(timenow):
    conn = get_connection()
    conn.execute("""
        delete from t_api_wldw where code in (select Dwdm from PubKszl);
        insert into t_api_wldw (
            id,
            code,
            name_chs,
            organizationcode,
            type,
            area,
            countryorregion,
            seclevel,
            seclevelid,
            state_asyncdeletestatus,
            state_isenabled,
            state_disabletime,
            timestamp_createdon,
            timestamp_lastchangedon,
            esun_api_update)
        select 'esun-' || substr(cast(uuid() as varchar), 6),Dwdm,Dwqc,Zzsh,'类别','地区','国家或地区',0,'BFPUBLIC','0',
            Syzt,
            null,STRPTIME(Jl_RQ, '%Y%m%d'),STRPTIME(Xg_RQ, '%Y%m%d'),'"""+timenow+"""'
            from PubKszl; 
        --update t_api_wldw set type = '空' where type is null;
        """)
    conn.close()
